//
//  HWTitleButton.m
//  01-黑马微博
//
//  Created by lanou3g on 15/9/7.
//  Copyright (c) 2015年 heima. All rights reserved.
//

#import "HWTitleButton.h"
#import "NSString+Ectentsion.h"
#import "HWAccountTool.h"
@implementation HWTitleButton

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont boldSystemFontOfSize:17];
        [self setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];
        [self setImage:[UIImage imageNamed:@"navigationbar_arrow_up"] forState:UIControlStateHighlighted];
        self.imageView.contentMode = UIViewContentModeCenter;

            }
    return self;
}

//目的：想在系统计算和设计完按钮尺寸后，再修改一次尺寸
//self.frame重写setframe
- (void)setFrame:(CGRect)frame{
    frame.size.width += 10;
    [super setFrame:frame];
    
}
- (void)layoutSubviews{
    [super layoutSubviews];
    //如果仅仅是调整按钮内部位置，那么我们在layoutsubview改变位置即可
    //1.计算titlelabel
    self.titleLabel.x = self.imageView.x;
    self.imageView.x = CGRectGetMaxX(self.titleLabel.frame) + 10;
}
- (void)setImage:(UIImage *)image forState:(UIControlState)state{
    [super setImage:image forState:state];
    [self sizeToFit];
}

- (void)setTitle:(NSString *)title forState:(UIControlState)state{
    [super setTitle:title forState:state];
    [self sizeToFit];
}
@end
